package Servlet;

import DAO.UserDAO;
import POJO.Response;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

/**
 * @author ysr2022
 * 用户登录
 *
 */
public class Login extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserDAO userDao = new UserDAO();
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        Response res;

        try{
            if(userDao.userNameExisted(username)){
                //tempData = new Servlet.CheckUsername.CheckUsernameData(true);
            }else {
                //tempDataa = new Servlet.CheckUsername.CheckUsernameData(false);
            }
            res = new Response(0,"查询成功",null);
        }catch(SQLException e){
            res = new Response(1001,"参数不正确",null);
        }


        resp.setContentType("text/json;charset=UtF-8");
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();
        String json = gson.toJson(res);
        out.println(json);
    }
}
